<template>
  <div class="container">
    <div class="background-container">
      <div class="animated-background" :style="{ backgroundImage: `url(${currentBackground})` }"></div>
    </div>

    <div class="content">
      <div class="glow-circle"></div>
      <h1>恭喜！发现了一个隐藏页面！</h1>
      <div class="info-panel" :class="{ expanded: infoExpanded }">
        <p>这是一个神秘的隐藏页面，只有有缘人才能看到。</p>
        <p>你可以在这里探索不同背景，感受不同的视觉体验。</p>
        <p>点击"切换背景"按钮可以查看不同的背景图片。</p>
        <p>点击"停止动画"可以暂停背景切换动画。</p>
      </div>
      <div class="buttons">
        <button @click="changeBackground" class="magic-button">
          <span>切换背景</span>
        </button>
        <button @click="toggleAnimation" class="magic-button">
          <span>{{ animationEnabled ? '停止动画' : '启动动画' }}</span>
        </button>
        <button @click="toggleInfoPanel" class="magic-button">
          <span>{{ infoExpanded ? '隐藏信息' : '显示更多信息' }}</span>
        </button>
      </div>

      <div class="floating-stars">
        <div v-for="star in stars" :key="star.id" class="star" :style="star.style"></div>
      </div>

      <div class="glowing-orbs">
        <div v-for="orb in orbs" :key="orb.id" class="orb" :style="orb.style"></div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, onMounted, onUnmounted } from 'vue';

export default {
  setup() {
    const backgrounds = [
      require('@/assets/login_bk_0.jpg'),
      require('@/assets/login_bk_1.jpg'),
      require('@/assets/login_bk_2.jpg'),
      require('@/assets/login_bk_3.jpg'),
      require('@/assets/login_bk_4.jpg'),
      require('@/assets/login_bk_5.jpg')
    ];

    const currentBackground = ref(backgrounds[0]);
    const backgroundsIndex = ref(0);
    const animationEnabled = ref(true);
    const stars = ref([]);
    const orbs = ref([]);
    const infoExpanded = ref(false);

    // 创建浮动星星
    function createStars() {
      stars.value = [];
      for (let i = 0; i < 30; i++) {
        stars.value.push({
          id: i,
          style: {
            left: `${Math.random() * 100}%`,
            top: `${Math.random() * 100}%`,
            width: `${Math.random() * 10 + 5}px`,
            height: `${Math.random() * 10 + 5}px`,
            opacity: Math.random(),
            animationDuration: `${Math.random() * 5 + 5}s`,
            animationDelay: `${Math.random() * 5}s`,
          }
        });
      }
    }

    // 创建发光的球体
    function createOrbs() {
      orbs.value = [];
      const colors = ['#ff6b6b', '#48dbfb', '#1dd1a1', '#feca57', '#5f27cd'];

      for (let i = 0; i < 8; i++) {
        orbs.value.push({
          id: i,
          style: {
            left: `${Math.random() * 80 + 10}%`,
            top: `${Math.random() * 80 + 10}%`,
            width: `${Math.random() * 40 + 20}px`,
            height: `${Math.random() * 40 + 20}px`,
            backgroundColor: colors[i % colors.length],
            opacity: Math.random() * 0.5 + 0.3,
            animationDuration: `${Math.random() * 20 + 10}s`,
            animationDelay: `${Math.random() * 5}s`,
          }
        });
      }
    }

    // 切换背景
    function changeBackground() {
      backgroundsIndex.value = (backgroundsIndex.value + 1) % backgrounds.length;
      currentBackground.value = backgrounds[backgroundsIndex.value];
    }

    // 自动切换背景
    const intervalId = ref(null);

    function startAutoChange() {
      if (animationEnabled.value) {
        if (intervalId.value) clearInterval(intervalId.value);
        intervalId.value = setInterval(changeBackground, 5000);
      }
    }

    // 切换动画状态
    function toggleAnimation() {
      animationEnabled.value = !animationEnabled.value;
      if (animationEnabled.value) {
        startAutoChange();
      } else {
        if (intervalId.value) clearInterval(intervalId.value);
      }
    }

    // 切换信息面板
    function toggleInfoPanel() {
      infoExpanded.value = !infoExpanded.value;
    }

    onMounted(() => {
      createStars();
      createOrbs();
      startAutoChange();
    });

    onUnmounted(() => {
      if (intervalId.value) clearInterval(intervalId.value);
    });

    return {
      currentBackground,
      changeBackground,
      toggleAnimation,
      animationEnabled,
      stars,
      infoExpanded,
      toggleInfoPanel,
      orbs
    };
  }
}
</script>

<style scoped>
.container {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.background-container {
  width: 100%;
  height: 100%;
  position: absolute;
}

.animated-background {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  transition: background-image 1s ease-in-out;
  z-index: 1;
}

.content {
  position: relative;
  z-index: 10;
  text-align: center;
  color: white;
  font-family: 'Arial', sans-serif;
  padding: 30px;
}

h1 {
  font-size: 3rem;
  margin-bottom: 20px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  animation: glow 2s infinite alternate;
  position: relative;
  display: inline-block;
  padding: 10px 20px;
}

.glow-circle {
  position: absolute;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(106, 17, 203, 0.2) 0%, rgba(37, 117, 252, 0) 70%);
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  z-index: -1;
  animation: pulse 4s infinite alternate;
}

.info-panel {
  font-size: 1.1rem;
  margin: 20px auto;
  max-width: 600px;
  background-color: rgba(0, 0, 0, 0.5);
  padding: 20px;
  border-radius: 15px;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
  max-height: 0;
  overflow: hidden;
}

.info-panel.expanded {
  opacity: 1;
  transform: translateY(0);
  max-height: 500px;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  margin: 30px 0;
}

.magic-button {
  background: linear-gradient(45deg, #6a11cb 0%, #2575fc 100%);
  border: none;
  padding: 12px 24px;
  color: white;
  font-size: 1.1rem;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.magic-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 7px 20px rgba(0, 0, 0, 0.4);
}

.magic-button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.magic-button span {
  position: relative;
  z-index: 1;
}

.magic-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, rgba(255, 255, 255, 0.1), transparent);
  transform: translateX(-150%);
  transition: transform 0.5s ease;
}

.magic-button:hover::before {
  transform: translateX(150%);
}

.star {
  position: absolute;
  background-color: white;
  border-radius: 50%;
  animation: float 10s infinite ease-in-out;
  box-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.orb {
  position: absolute;
  border-radius: 50%;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
  animation: float 20s infinite ease-in-out;
  z-index: 5;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0) translateX(0) rotate(0deg);
  }
  25% {
    transform: translateY(-20px) translateX(20px) rotate(5deg);
  }
  50% {
    transform: translateY(0) translateX(0) rotate(0deg);
  }
  75% {
    transform: translateY(20px) translateX(-20px) rotate(-5deg);
  }
}

@keyframes glow {
  0% {
    text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #6a11cb, 0 0 40px #6a11cb;
  }
  100% {
    text-shadow: 0 0 5px #fff, 0 0 15px #fff, 0 0 25px #2575fc, 0 0 35px #2575fc;
  }
}

@keyframes pulse {
  0% {
    transform: translateX(-50%) scale(1);
    opacity: 0.6;
  }
  100% {
    transform: translateX(-50%) scale(1.1);
    opacity: 0.3;
  }
}

@media (max-width: 768px) {
  h1 {
    font-size: 2rem;
  }

  .buttons {
    flex-direction: column;
    gap: 10px;
  }
}
</style>